<?php
/*
 * @Descripttion: 第三方开放接口查询token
 * @version: v1
 * @Author: Terry
 * @Date: 2021-10-11 12:20:07
 * @LastEditors: Terry
 * @LastEditTime: 2024-10-03 09:45:18
 */
declare (strict_types = 1);

namespace app\openApi\middleware;

use think\facade\Db;

class Log
{
    /*
     * 处理请求
     *
    * @param \think\Request $request
     * @param \Closure       $next
     * @return Response
     */
    public function handle($request, \Closure $next){
        $response = $next($request);
        $postData = $request->post();
        
        $returnData = $response->getData();
        if(!isset($returnData['data'])){
            $returnData = [
                'code'=>FAIL,
                'message'=>'系统发生错误',
                'data'=>[],
            ];
        }
        $data = [
            'method'=>$request->pathinfo(),
            'postData' => json_encode($postData['data']),
            'sign' => $postData['sign'],
            'appId' => $postData['appId'],
            'timestamp' => $postData['timestamp'],
            'code' => $returnData['code'] ,
            'message' => $returnData['message'],
            'data' => json_encode($returnData['data']),
            'ip' => getClientIp(),
        ];

        DB::table('integratot_log')->insert($data);
        return $response;
    }

}

